package cn.ds.assets.module.assets.dal.mysql.metadataJobInstance;

import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDate;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ds.assets.framework.mybatis.core.mapper.BaseMapperX;
import cn.ds.assets.module.assets.dal.dataobject.metadataJobInstance.BaseMetadataJobInstanceDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ds.assets.module.assets.controller.admin.metadataJobInstance.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 元数据管理-元数据采集作业实例 Mapper
 *
 * @author admin
 */
@Mapper
public interface BaseMetadataJobInstanceMapper extends BaseMapperX<BaseMetadataJobInstanceDO> {

    default PageResult<BaseMetadataJobInstanceDO> selectPage(BaseMetadataJobInstancePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BaseMetadataJobInstanceDO>()
                .eqIfPresent(BaseMetadataJobInstanceDO::getJobId, reqVO.getJobId())
                .eqIfPresent(BaseMetadataJobInstanceDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getBusinessDate, reqVO.getBusinessDate())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getEndTime, reqVO.getEndTime())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getRuntime, reqVO.getRuntime())
                .eqIfPresent(BaseMetadataJobInstanceDO::getMsg, reqVO.getMsg())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataJobInstanceDO::getProjectId, reqVO.getProjectId())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getNextTime, reqVO.getNextTime())
                .eqIfPresent(BaseMetadataJobInstanceDO::getJobCode, reqVO.getJobCode())
                .inIfPresent(BaseMetadataJobInstanceDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataJobInstanceDO::getId));
    }

    default List<BaseMetadataJobInstanceDO> selectList(BaseMetadataJobInstanceExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BaseMetadataJobInstanceDO>()
                .eqIfPresent(BaseMetadataJobInstanceDO::getJobId, reqVO.getJobId())
                .eqIfPresent(BaseMetadataJobInstanceDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getBusinessDate, reqVO.getBusinessDate())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getEndTime, reqVO.getEndTime())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getRuntime, reqVO.getRuntime())
                .eqIfPresent(BaseMetadataJobInstanceDO::getMsg, reqVO.getMsg())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataJobInstanceDO::getProjectId, reqVO.getProjectId())
                .betweenIfPresent(BaseMetadataJobInstanceDO::getNextTime, reqVO.getNextTime())
                .eqIfPresent(BaseMetadataJobInstanceDO::getJobCode, reqVO.getJobCode())
                .inIfPresent(BaseMetadataJobInstanceDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataJobInstanceDO::getId));
    }

    @Update("UPDATE assets_metadata_job_instance SET deleted = 1, update_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}
